package com.tio.server.web.controller;

import cn.hutool.core.util.IdUtil;
import com.zengtengpeng.annotation.EnableCache;
import lombok.extern.log4j.Log4j2;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Log4j2
@Controller
@RequestMapping("/cache")
@EnableCache(value = {"userName"})
public class RedissonCacheController {


    //    @Cacheable：主要用于 “查询” 功能
    //    @CachePut：主要用于 “修改” 功能
    //    @CacheEvict：主要用于 “删除” 功能

    /**
     * 增加
     * @return long
     */
    @RequestMapping("/query")
    @Cacheable(cacheNames = "userName")
    @ResponseBody
    public String query() {
        return IdUtil.simpleUUID();
    }

    /**
     * 删除
     * @return long
     */
    @RequestMapping("/update")
    @ResponseBody
    @CachePut(cacheNames = "userName")
    public String update() {
        return IdUtil.simpleUUID();
    }

    /**
     * 删除
     * @return long
     */
    @RequestMapping("/dell")
    @ResponseBody
    @CacheEvict(cacheNames = "userName")
    public boolean dell() {
        return true;
    }

}
